import jenkins.model.*
import hudson.security.*

def adminUsername = 'admin' // 设置你想要的用户名
def adminPassword = 'Abcd#1234' // 设置你想要的密码
def instance = Jenkins.getInstance()

// 创建安全领域
def realm = new HudsonPrivateSecurityRealm(false)
realm.createAccount(adminUsername, adminPassword)

// 设置安全领域
instance.setSecurityRealm(realm)

// 设置授权策略，赋予管理员所有权限
def strategy = new FullControlOnceLoggedInAuthorizationStrategy()
strategy.setAllowAnonymousRead(false)
instance.setAuthorizationStrategy(strategy)

// 保存设置
instance.save()
println("Admin user created with username ${adminUsername}")